import java.util.HashMap;
import java.util.Map;

/**
 * Created With IntelliJ IDEA
 * Description:leetcode:1. 两数之和
 * <a href="https://leetcode.cn/problems/two-sum/">...</a>
 * User: DELL
 * Data: 2023-03-06
 * Time: 22:13
 */
public class Solution {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> hashMap = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (hashMap.containsKey(target-nums[i])) {
                return new int[]{hashMap.get(target - nums[i]), i};
            } else {
                hashMap.put(nums[i],i);
            }
        }
        return new int[0];
    }
}